/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import dao.BinhLuanDAO;
import dao.DienThoaiDAO;
import dao.ThongTinSanPhamDAO;
import dao.util.HibernateUtil;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.tools.Diagnostic;
import pojo.Dienthoai;
import org.hibernate.Query;
import org.hibernate.Session;
import pojo.Binhluan;
import pojo.Thongtinsanpham;
import template.choosePage; 
/**
 *
 * @author Minh Tien
 * Xử lý hiển thị thông tin 1 điện thoại và
 * danh sach cac bình luận về điện thoại này
 * cho phép add 1 bình luận
 */
@ManagedBean (name="detailmobile")
@SessionScoped
public class DetailMobile {


    private static Thongtinsanpham thongtin1sanpham= null;
    private static int madienthoai = -1;// dùng mã điện thoại
    private static ArrayList<Binhluan> danhsachbinhluan = null; // lay danh sach cac binh luan theo dien thoai
    private static Dienthoai dt=null;
    private static ArrayList<Dienthoai> danhsach5dienthoai = null;
    public Dienthoai getDT()
    {
        return dt;
    }
    public void setDT(Dienthoai d)
    {
        dt=d;
        
    }
    public DetailMobile() 
    {
    }
    
/////////////////////////////////////////////////////////////////////////////////////
    public Thongtinsanpham getThongtin1sanpham() {
        return thongtin1sanpham;
    }

    public void setThongtin1sanpham(int ma) // dùng mã diện thoại lấy 
    {  
        madienthoai=ma;
        choosePage.page="ChiTietDienThoai";
        ThongTinSanPhamDAO dtdao=new ThongTinSanPhamDAO();//thong tin ( dien thoai ; pin,hinh anh.....)
        thongtin1sanpham = dtdao.get(ma);
   
        BinhLuanDAO bldao = new BinhLuanDAO();// lay binh luan cho dien thoai do
        danhsachbinhluan= bldao.getBinhLuan(ma);
        
        ///////////////////////////////////////////
        DienThoaiDAO dtdaotam = new DienThoaiDAO();
        danhsach5dienthoai =  dtdaotam.getDanhSach5DienThoaiCungLoai(ma);
        System.out.println("danh sach 5 dien thoai mobile 00000000000 co: \n");
        for(int i=0 ; i< danhsach5dienthoai.size();i++)
        {
            System.out.println(danhsach5dienthoai.get(i).getTendienthoai());
        }
        for(int i=0 ; i<10; i++)         
        {
        System.out.println(madienthoai);
        }
        ///////////////////////////////////////////
        /// tang so luong 1 lan xem
        DienThoaiDAO dao=new  DienThoaiDAO();
        dt =dao.get(ma);
        dt.setSoluongxem(dt.getSoluongxem()+1);
        dao.saveorupdate(dt);
        
        
    }
    
    public ArrayList<Dienthoai> getDanhSach5DienThoai()
    {
        return danhsach5dienthoai;
    }
/////////////////////////////////////////set va get ma dien thoai de lay thong tin/////////////////////////////////////////////////
    public void setMadienthoai(int aMadienthoai) {
        madienthoai = aMadienthoai;
    }

    public int getMadienthoai() {
        
        return madienthoai;
    }
 /////////////////////////////////////////danh sach binh luan di theo dien thoai///////////////////////////////////////////////   
    public ArrayList<Binhluan> getDanhsachbinhluan() {
        return danhsachbinhluan;
    }

    
 ///////////////////////////////////////nguoi dung add 1 comment //////////////////////////////////////////////   
    private static String Loibinhluan="";

    public String getLoibinhluan() {
        return Loibinhluan;
    }

    public void setLoibinhluan(String aLoibinhluan) {
        Loibinhluan = aLoibinhluan;
    }
    public void setAddbinhluan()
    {
        if(controller.login.CheckTaiKhoan.taikhoan != null)
        {
            BinhLuanDAO bldao = new BinhLuanDAO();
            bldao.addBinhLuan(madienthoai, Loibinhluan, controller.login.CheckTaiKhoan.taikhoan.getTendangnhap());
            BinhLuanDAO bldaotam = new BinhLuanDAO();// lay binh luan cho dien thoai do
            danhsachbinhluan= bldaotam.getBinhLuan(madienthoai);
            choosePage.page="ChiTietDienThoai";
        }
    }
    
       
}
